<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        body {
            background-color: lavender;
        }

        #main {
            width: 600px;
            height: 400px;
            border: 0px solid gray;
            margin: 0 auto;
            margin-top: 20px;
            text-align: center;
            background-color: lemonchiffon;
            box-shadow: 0px 1px 1px greenyellow;
        }

        #main h1 {
            margin: 40px;
        }

        #main input {
            margin-bottom: 10px;
            line-height: 30px;
            height: 30px;
            width: 320px;
        }

        #main #btn {
            width: 230px;
            margin-top: 40px;
            height: 40px;
        }
    </style>
</head>

<body>
<div id="main">
    <h1>修改密码</h1>
    <span>输入旧密码：</span>
    <input type="password" id="oldpasswd"><br>
    <span>输入新密码：</span>
    <input type="password" id="newpasswd"><br>
    <span>确认新密码：</span>
    <input type="password" id="newpasswd2"><br>

    <input type="button" id="btn" value="修改密码">
</div>

<script src="../js/jquery-3.6.0.js"></script>

<script type="text/javascript">
    $("#btn").click(function () {
        var oldpasswd = $("#oldpasswd").val();
        var newpasswd = $("#newpasswd").val();
        var newpasswd2 = $("#newpasswd2").val();

        var url = location.href;
        var eid = url.substring(url.lastIndexOf("=") + 1);

        if(newpasswd != newpasswd2) {
            alert("两次密码不一致");
            return false;
        }
        //发送请求
        $.ajax({
            url: "/crm/updatePassword",
            type: "post",
            data:{
                eid: eid,
                passwd: oldpasswd,
                newpasswd: newpasswd
            },
            success: function (result) {
                if(result.data == 1){
                    alert(result.message);
                    window.parent.location.href = "../login.html";
                    return;
                }
                if(result.data == -1){
                    alert(result.message);
                    return;
                }else {
                    alert(result.message);
                }
            }
        })

    });
</script>

</body>

</html>
